package com.joyance.test_servlet.servlet;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestHttpServletResponse extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("HttpServletResponse========");
		System.out.println("test addCookie begin========");
		Cookie[] cookies=req.getCookies();
		for(Cookie cookie:cookies){
			System.out.println("name="+cookie.getName()+",value="+cookie.getValue());
		}
		System.out.println("test addCookie end========");
		//containsHeader
		System.out.println("resp.containsHeader(\"age\")="+resp.containsHeader("age"));
		//encodeRedirectURL
		System.out.println("encodeRedirectURL="+req.getRequestURI()+"?"+req.getQueryString());
		System.out.println(URLDecoder.decode(req.getQueryString()));
		System.out.println(req.getParameter("name")+"==="+req.getParameter("age"));
		//sendError
		resp.sendError(resp.SC_BAD_GATEWAY, "看到错误信息了吗");
		//setStatus
		resp.setStatus(resp.SC_OK, "成功了吗");
	}
	
}
